#include "EventPoller.h"
#include "AntTweakBarManager.h"
#include <assert.h>

void EventPoller::Update(const MSG& msg)
{
	//MSG msg;
	//int poll = SDL_PollEvent(&e);
	if (msg.message)
	{

		//if (msg.wParam == VK_ESCAPE)
		//{
		//	TwTerminate();
  //          PostQuitMessage( 0 );
		//}

		Handlers handlers = m_handlers;
		for (Handlers::iterator it = handlers.begin(); it != handlers.end(); ++it) 
		{
			(*it)->HandleEvent(msg);
		}
	}
	//std::string r = SDL_GetError();
}

void EventPoller::AddHandler(EventHandler* eh)
{
	m_handlers.insert(eh);	
}

void EventPoller::RemoveHandler(EventHandler* eh)
{
//	assert(m_handlers.find(eh) != m_handlers.end());

	if (m_handlers.find(eh) != m_handlers.end())
	{
		m_handlers.erase(eh);
	}
}